import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;

import poset.PosetSpace;
import poset.RectangularPosetSpace;


@SuppressWarnings("serial")
public class PosetSpaceViewer extends JPanel {
	
	Timer timer;
	protected PosetSpace posetSpace;
	private int iters = 0;
	private double tension = 0;
	private double tensionGrowth = 1;
	private double avgTension = 0;
	
	public PosetSpaceViewer(PosetSpace ps){
		this.posetSpace = ps;
		posetSpace.initialize();
		setBackground(Color.BLACK);
		
		timer = new Timer(0, new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				posetSpace.next();
				iters++;
				tensionGrowth = 10.0/(10+iters);
				tension = posetSpace.getTension();
				avgTension = tension*tensionGrowth + avgTension*(1-tensionGrowth);
				repaint();
			}
		});
	}
	
	public void start(){
		timer.start();
	}
}
